package fudan.se.project.service.infrastructure.entity.conference.production;

import fudan.se.project.domain.conference.production.Paper;
import fudan.se.project.domain.conference.production.Writer;
import fudan.se.project.repository.entity.conference.production.WriterRepository;
import fudan.se.project.service.infrastructure.base.IEntityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;

@Slf4j
@Service
public class WriterService implements IEntityService<Writer> {

    private WriterRepository writerRepository;

    public WriterService(WriterRepository writerRepository) {
        this.writerRepository = writerRepository;
    }


    @Override
    public Writer findById(long id) {
        return writerRepository.findById(id);
    }

    @Override
    public Writer save(Writer writer) {
        return this.writerRepository.save(writer);
    }
    @Override
    public Iterable<Writer> saveAll(Collection<Writer> writers) {
        return this.writerRepository.saveAll(writers);
    }

    @Transactional
    public void deleteAllByPaper(Paper paper){
        writerRepository.deleteAllByPaper(paper);
    }
}
